package com.rabbitmq.producer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Thomas
 * @Date: 2024-01-14  19:43:53
 * @Description:
 */
@Configuration
public class RabbitMQConfig {

    // 1. 声明交换机fanout【创建交换机】
    @Bean
    public FanoutExchange fanoutExchange(){
        // 持久化 不自动删除
        return new FanoutExchange("fanout_order_exchange", true, false);
    }
    // 2. 声明队列 sms.fanout.queue  email.fanout.queue  message.fanout.queue 【创建队列】
    @Bean
    public Queue sms(){
        return new Queue("sms.fanout.queue", true);
    }
    @Bean
    public Queue email(){
        return new Queue("email.fanout.queue", true);
    }
    @Bean
    public Queue message(){
        return new Queue("message.fanout.queue", true);
    }
    // 3. 完成绑定关系
    @Bean
    public Binding smsBinding(){
        return BindingBuilder.bind(sms()).to(fanoutExchange());
    }
    @Bean
    public Binding emailBinding(){
        return BindingBuilder.bind(email()).to(fanoutExchange());
    }
    @Bean
    public Binding massgeBinding(){
        return BindingBuilder.bind(message()).to(fanoutExchange());
    }

}
